package com.nowcoder.community.utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/*
* 从 cookie 中获取值
* */
public class CookieUtils {
    public static String getValue(HttpServletRequest request, String name){
        if (request == null || name == null)
            return null;

        Cookie[] cookies = request.getCookies();
        if (cookies == null) return null;
        for (Cookie cookie: cookies){
            if (cookie.getName().equals(name)) return cookie.getValue();
        }
        return null;
    }
}
